package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.vo.applet.AppletUserExpensesVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BdmExpensesDetailMapper;
import com.ruoyi.system.domain.BdmExpensesDetail;
import com.ruoyi.system.service.IBdmExpensesDetailService;

/**
 * 支出明细Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-14
 */
@Service
public class BdmExpensesDetailServiceImpl implements IBdmExpensesDetailService 
{
    @Autowired
    private BdmExpensesDetailMapper bdmExpensesDetailMapper;

    /**
     * 查询支出明细
     * 
     * @param id 支出明细主键
     * @return 支出明细
     */
    @Override
    public BdmExpensesDetail selectBdmExpensesDetailById(Long id)
    {
        return bdmExpensesDetailMapper.selectBdmExpensesDetailById(id);
    }

    /**
     * 查询支出明细列表
     * 
     * @param bdmExpensesDetail 支出明细
     * @return 支出明细
     */
    @Override
    public List<BdmExpensesDetail> selectBdmExpensesDetailList(BdmExpensesDetail bdmExpensesDetail)
    {
        return bdmExpensesDetailMapper.selectBdmExpensesDetailList(bdmExpensesDetail);
    }

    /**
     * 新增支出明细
     * 
     * @param bdmExpensesDetail 支出明细
     * @return 结果
     */
    @Override
    public int insertBdmExpensesDetail(BdmExpensesDetail bdmExpensesDetail)
    {
        bdmExpensesDetail.setCreateTime(DateUtils.getNowDate());
        return bdmExpensesDetailMapper.insertBdmExpensesDetail(bdmExpensesDetail);
    }

    /**
     * 修改支出明细
     * 
     * @param bdmExpensesDetail 支出明细
     * @return 结果
     */
    @Override
    public int updateBdmExpensesDetail(BdmExpensesDetail bdmExpensesDetail)
    {
        bdmExpensesDetail.setUpdateTime(DateUtils.getNowDate());
        return bdmExpensesDetailMapper.updateBdmExpensesDetail(bdmExpensesDetail);
    }

    /**
     * 批量删除支出明细
     * 
     * @param ids 需要删除的支出明细主键
     * @return 结果
     */
    @Override
    public int deleteBdmExpensesDetailByIds(Long[] ids)
    {
        return bdmExpensesDetailMapper.deleteBdmExpensesDetailByIds(ids);
    }

    /**
     * 删除支出明细信息
     * 
     * @param id 支出明细主键
     * @return 结果
     */
    @Override
    public int deleteBdmExpensesDetailById(Long id)
    {
        return bdmExpensesDetailMapper.deleteBdmExpensesDetailById(id);
    }

    /**
     * 小程序用户支出明细列表
     * @param bdmExpensesDetail
     * @return
     */
    @Override
    public List<AppletUserExpensesVo> selectUserExpensesDetailList(BdmExpensesDetail bdmExpensesDetail) {
        List<AppletUserExpensesVo> appletUserExpensesVoList = new ArrayList<>();
        Long sysUid = SecurityUtils.getUserId();
        bdmExpensesDetail.setSysUserid(sysUid);
        List<BdmExpensesDetail> bdmExpensesDetailList = bdmExpensesDetailMapper.selectBdmExpensesDetailList(bdmExpensesDetail);
        if (StringUtils.isNotEmpty(bdmExpensesDetailList)) {
            for (BdmExpensesDetail detail : bdmExpensesDetailList) {
                AppletUserExpensesVo vo = new AppletUserExpensesVo();
                vo.setExpensesName(detail.getType());
                vo.setExpensesTime(detail.getCreateTime());
                vo.setExpensesMoney(detail.getAmount());
                appletUserExpensesVoList.add(vo);
            }
        }
        return appletUserExpensesVoList;
    }
}
